
Partial Class Controls_UserProfile
    Inherits System.Web.UI.UserControl
    Private _username As String = ""
    Public Property UserName() As String
        Get
            Return _username
        End Get
        Set(ByVal value As String)
            _username = value
            loadprofile()
        End Set
    End Property

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Me.Page.RegisterRequiresControlState(Me)
        lblusername.Text = Me.UserName
    End Sub
    Protected Overrides Sub LoadControlState(ByVal savedState As Object)
        Dim ctlState() As Object = savedState
        MyBase.LoadControlState(savedState)
        _username = CType(ctlState(1), String)
    End Sub
    Protected Overrides Function SaveControlState() As Object
        Dim ctlState(2) As Object
        ctlState(0) = MyBase.SaveControlState()
        ctlState(1) = _username
        Return ctlState
    End Function
    Public Sub SaveProfile()
        Dim p As ProfileCommon
        p = HttpContext.Current.Profile
        If _username.Length > 0 Then
            p = p.GetProfile(_username)
        End If
        
        p.Address.Street = txtStreet.Text
        p.Address.City = txtCity.Text
        p.Address.State = txtState.Text
        p.Address.Zip = txtZip.Text
        p.Save()
    End Sub
    Private Sub loadprofile()
        Dim p As ProfileCommon
        p = HttpContext.Current.Profile
        If _username.Length > 0 Then
            p = p.GetProfile(_username)
        End If
        lblusername.Text = p.UserName
       
        txtStreet.Text = p.Address.Street
        txtCity.Text = p.Address.City
        txtState.Text = p.Address.State
        txtZip.Text = p.Address.Zip

    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Me.IsPostBack Then
            Me.DataBind()
            loadprofile()
        End If
    End Sub
End Class
